package cloud.shyidong.admin.controller;

import cloud.shyidong.admin.service.SelfService;
import cloud.shyidong.core.Result;
import cloud.shyidong.system.request.InfoUpdatePasswordRequest;
import cloud.shyidong.system.request.InfoUpdateRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @Description TODO
 * @Author syd
 * @Date 2023/10/21
 */
@RestController
@Slf4j
public class SelfController {
    
    private SelfService selfService;
    
    @Autowired
    public void setSelfService(SelfService selfService) {
        this.selfService = selfService;
    }
    
    /**
     * 查询登录信息
     *
     * @param token
     * @return
     */
    @GetMapping("/get")
    public Result get() {
        return selfService.get();
    }
    
    /**
     * 查询菜单树
     *
     * @return
     */
    @GetMapping("/trees")
    public Result trees() {
        return selfService.getTreeList();
    }
    
    /**
     * 登录用户更新信息
     *
     * @param infoUpdateRequest
     */
    @PostMapping("/update")
    public Result update(@RequestBody @Valid InfoUpdateRequest infoUpdateRequest) {
        if (log.isDebugEnabled()) {
            log.debug("update param >>> {}", infoUpdateRequest);
        }
        return selfService.update(infoUpdateRequest);
    }
    
    /**
     * 登录用户修改密码
     *
     * @param infoUpdatePasswordRequest
     */
    @PostMapping("/update-pwd")
    public Result updatePassword(@RequestBody @Valid InfoUpdatePasswordRequest infoUpdatePasswordRequest) {
        if (log.isDebugEnabled()) {
            log.debug("updatePassword param >>> {}", infoUpdatePasswordRequest);
        }
        return selfService.updatePassword(infoUpdatePasswordRequest);
    }
    
    /**
     * 登录用户退出系统
     */
    @GetMapping("/logout")
    public Result logout() {
        return selfService.logout();
    }
    
    
}
